﻿<UserControl x:Class="ViewTableViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" xml:lang="fr-FR"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid Name="MainGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <StackPanel Orientation="Horizontal" Margin="5" >
                <Button Content="Trier la table" Padding="2" Margin="2" Name="BtTrier" Click="BtTrier_Click" />
                <Button Content="Exporter vers Excel" Padding="2" Margin="2" Command="{Binding}" CommandParameter="_export_table_to_excel_" />
                <Button Content="Importer depuis Excel" Padding="2" Margin="2" Command="{Binding}" CommandParameter="_import_table_from_excel_"/>
            </StackPanel>
            <DataGrid DataContext="{Binding}"   ItemsSource="{Binding DataView}" Grid.Row="1" CanUserDeleteRows="False" CanUserAddRows="False" ClipboardCopyMode="IncludeHeader" Name="DGrid" EnableColumnVirtualization="True" IsReadOnly="True">
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="DataGridColumnHeader" >
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Background" Value="White" />
                        <Setter Property="ContentTemplate" >
                            <Setter.Value>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <TextBlock Grid.Column="0" Margin="2" VerticalAlignment="Center"   Text="{Binding}" />
                                        <Button Grid.Column="1" Margin="2"   Content=" ... " VerticalAlignment="Center" Background="White" CommandParameter="{Binding}" Command="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext}" />
                                    </Grid>

                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGrid.ColumnHeaderStyle>
            </DataGrid>
        </Grid>
        <Grid Name="SortGrid" Background="#3F000000"  >
            <Grid.Visibility>
                <Binding Path="ModeTri" Mode="TwoWay">
                    <Binding.Converter>
                        <BooleanToVisibilityConverter />
                    </Binding.Converter>
                </Binding>
            </Grid.Visibility>
            <Grid MinHeight="150" MinWidth="100" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ListBox Name="SortLst"  Padding="5" Background="White"  >
                    
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="Template" >
                                <Setter.Value>
                                    <ControlTemplate TargetType="ListBoxItem">
                                        <Grid>
                                            <Grid.ColumnDefinitions >
                                                <ColumnDefinition />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                                <CheckBox IsChecked="{Binding Sort}" Margin="2" />
                                                <TextBlock Text="{Binding Name}" Margin="2" />
                                            </StackPanel>
                                            <StackPanel Grid.Column="1" VerticalAlignment="Center" >
                                                <Button DataContext="{Binding}" Content="+1"  Margin="1" Padding="1" FontSize="8" Background="White" Click="UpButton_Click"/>
                                                <Button DataContext="{Binding}" Content="-1"  Margin="1" Padding="1" FontSize="8" Background="White" Click="DownButton_Click"/>
                                            </StackPanel>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
                <StackPanel Orientation="Horizontal"  Grid.Row="1" HorizontalAlignment="Right">
                    <Button Content=" OK " Margin="2" Name="SortOkBt" Click="SortOkBt_Click"/>
                    <Button Content=" KO "  Margin="2" Name="SortKoBt" Click="SortKoBt_Click" />
                </StackPanel>

            </Grid>
        </Grid>
    </Grid>
</UserControl>
